<?php
class B2b_Models_Dao_Pdo_Mysql_Comment extends Tomato_Model_Dao
    implements B2b_Models_Interface_Comment
{
    public function convert($entity)
    {
        return new B2b_Models_Comment($entity);
    }

    public function getCByBId($exp = null, $offset = null, $count = null){
        $select = $this->_conn
                        ->select()
                        ->from(array('bc' => $this->_prefix . 'enterprise_blog_comment'));
        if ($exp) {
            if (isset($exp['blog_id'])) {
                $select->where("bc.blog_id =?", $exp['blog_id']);
            }
        }
        $select->order("bc.id ASC");
        if(null != $count){
            $select->limit($count, $offset);
        }
        $rs = $select->query()
                     ->fetchAll();
        return new Tomato_Model_RecordSet($rs, $this);
    }

    public function add($comment){
        $this->_conn->insert($this->_prefix . 'enterprise_blog_comment',
                            array(
                                'user_id' => $comment->user_id,
                                'blog_id' => $comment->blog_id,
                                'content' => $comment->content,
                                'date'    => $comment->date,
                            ));
        return $this->_conn->lastInsertId($this->_prefix . 'enterprise_blog_comment');
    }

    public function delete($id){
        return $this->_conn->delete($this->_prefix . 'enterprise_blog_comment',
                            array(
                                'id = ?' => $id
                            ));
    }
}
